package com.ai.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ai.common.controller.BaseController;
import com.ai.common.model.Result;
import com.ai.mmd.reviewed.dto.YhxxDTO;
import com.ai.service.reviewed.model.YhxxModel;
import com.ai.service.reviewed.service.IYhxxService;

/**
 * 
 * Class Name : RegisterController<br>
 * 
 * Description : 注册Controller类<br>
 * 
 * @see
 *
 */
@RequestMapping("login")
@Controller("com.ai.controller.RegisterTwoController")
public class RegisterTwoController extends BaseController {
	
	@Resource(name = "iyhxxService")
	private IYhxxService iyhxxService;

	@Value("${mainDomain}")
	private String mainDomain;

	/**
	 * Description ：注册引导
	 * @throws Exception 
	 */
	@RequestMapping("/registertwo")
	public String registertwo(@RequestParam(required = true) String userid) throws Exception {
		Result result = new Result();
		result.addAttribute("userid", userid);
		result.rendering();
		
		return "/front/frontgoods/registertwo";
	}
	
	@RequestMapping(value ="/register/rgtwo", method = RequestMethod.POST)
	public @ResponseBody Map<String,Object> rgtwo(@ModelAttribute YhxxModel yhxx)throws Exception {
	
		Map<String,Object> map = new HashMap<String,Object>();
		
		YhxxDTO yhxxDTO = new YhxxDTO();
		List<YhxxModel> ym = iyhxxService.getList(new YhxxDTO(yhxx.getYhid()));
		if(ym.size()>0){
			map.put("message", -3);
			return map;
		}
		
		yhxxDTO.setQyqc(yhxx.getQyqc());
		YhxxModel yhxxModel = iyhxxService.getOne(yhxxDTO);
		if (yhxxModel!=null) {
			map.put("message", -1);
			return map;
		}
				
		yhxx.setYlzd2("0");
		yhxx.setCjsj(new Date());
		iyhxxService.insert(yhxx);
		
		map.put("message", 1);
		return map;
	}
	
	
	/**
	 * Description ：注册提交
	 * @throws Exception 
	 */
	/* @RequestMapping(value ="/registerconfig", method = RequestMethod.POST)
	public @ResponseBody Map<String,Object> registerconfig(Dlxx dlxx) throws Exception {
		
		Map<String,Object> map = new HashMap<String,Object>();
		
		DlxxKey dlxxKey = new DlxxKey();
		dlxxKey.setYhid(dlxx.getYhid());
		Dlxx dlxxByYhid = dlxxService.selectByPrimaryKey(dlxxKey);
		if (dlxxByYhid!=null) {
			map.put("message", "用户名已存在");
			return map;
		}
		
		Dlxx dlxxBySjh = dlxxService.selectByPhone(dlxx);
		if (dlxxBySjh!=null) {
			map.put("message", "手机号已存在");
			return map;
		}
		
		String token = dlxxService.insertSelective(dlxx);
		if (token!=null) {
			map.put("message", 1);
			session.setAttribute("yhid", dlxx.getYhid());
			session.setAttribute("token", token);
		} else {
			map.put("message", -1);
		}
		
		return map;
	}*/
	
	
}
